package com.jereh.weibo.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.jereh.weibo.R;

import java.util.Timer;
import java.util.TimerTask;

import cn.jpush.android.api.JPushInterface;

public class WelcomeActivity extends AppCompatActivity {

    private SharedPreferences sharedPreferences;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        sharedPreferences=getSharedPreferences("set",MODE_PRIVATE);
        activityJump();
    }

    private void activityJump(){
        if(sharedPreferences.getBoolean("first",true)) {
            SharedPreferences.Editor editor=sharedPreferences.edit();
            editor.putBoolean("first", false);
            editor.commit();
            Timer timer=new Timer();
            TimerTask task=new TimerTask() {
                @Override
                public void run() {
                    startActivity(new Intent(WelcomeActivity.this,GuideActivity.class));
                    finish();
                }
            };
            timer.schedule(task, 1000 * 1);
        } else {
            final Intent it = new Intent(this, MainActivity.class); //你要转向的Activity
            Timer timer = new Timer();
            TimerTask task = new TimerTask() {
                @Override
                public void run() {
                    startActivity(it); //执行
                    finish();
                }
            };
            timer.schedule(task, 1000 * 1);
            //intent.setClass(WelcomeActivity.this, HomeActivity.class);
        }

//        startActivity(intent);

    }

    @Override
    protected void onResume() {
        super.onResume();
        JPushInterface.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        JPushInterface.onPause(this);
    }
}
